<div class="content-form">
    <h2><?php echo $this->titulo; ?></h2>

    <?php
    $readonly = $this->data['PRS_ID'] > 0 ? 'readonly=""' : '';
    $disabled = $this->data['PRS_ID'] > 0 ? 'disabled=""' : '';
    ?>

    <?php if ($this->data['PRS_ID'] <= 0) { ?>
        <div id="content-form">
            <form id="form_list" name="form_list" method="post">
                <div class="row">
                    <div class="col-md-4">
                        <dt><label>Serviço</label></dt>   
                        <dd>
                            <input type="hidden" id="SER_ID" name="SER_ID" value="" class="find_id">
                            <input type="text" id="SER_NOM" name="SER_NOM" class="form-control w-auto find" value="">
                        </dd>
                    </div>
                    <div class="col-md-2">
                        <dt><label>R$</label></dt>   
                        <dd>
                            <input type="text" id="SER_VLR" name="SER_VLR" class="form-control w-auto find_prc" value="" readonly="">
                        </dd>
                    </div>
                    <div class="col-md-1">
                        <dt><label>Qtd</label></dt>   
                        <dd>
                            <input type="text" id="SER_QTD" name="SER_QTD" class="form-control w-auto numero find_qtd" value="" maxlength="5">
                        </dd>
                    </div>
                    <div class="col-md-2">
                        <dt><label>Preço</label></dt>   
                        <dd>
                            <input type="text" id="SER_VLRTOT" name="SER_VLRTOT" class="form-control w-auto" value="" readonly="">
                        </dd>
                    </div>
                    <div class="col-md-1 row-btn">
                        <button type="button" class="btn btn-primary" id="lancar">
                            <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
                            Lançar
                        </button>
                    </div>
                </div>

                </dd>
            </form>
        </div>
    <?php } ?>
</div>

<form id="form_edt" name="form_edt" enctype="application/x-www-form-urlencoded" action="" method="post" novalidate="novalidate">
    <div class="table-responsive">

        <div class="form-group">
            <table id="tlist" class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>Serviço</th>
                        <th>Qtd / R$</th>
                        <th>Preço</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody id="lista">
                    <?php
                    if (isset($this->serv))
                        foreach ($this->serv as $ser) {
                            ?>
                            <tr>
                                <td><?php echo $ser['SER_NOM']; ?></td>
                                <td><?php echo $ser['PSS_QTD'].' x R$ '.tools::float_to_money($ser['PSS_VLR']/$ser['PSS_QTD']); ?></td>
                                <td><?php echo 'R$ '.tools::float_to_money($ser['PSS_VLR']); ?></td>

                                <td>
                                    <input type="hidden" name="SER_ID[]" value="">
                                    <input type="hidden" name="SER_VLR[]" value="">
                                    <input type="hidden" name="SER_VLRTOT[]" value="">
                                    <input type="hidden" name="SER_QTD[]" value="'">
                                </td>

                            </tr>
                        <?php } ?>
                </tbody>
            </table>
        </div>

        <div class="form-group">
            <dt><label>Cliente</label></dt>   
            <dd> 
                <?php
                $query = 'SELECT SQL_CACHE CLI_ID,CLI_NOM FROM CLIENTES WHERE CLI_STA = 1 ORDER BY CLI_NOM ASC';
                $rows = $this->db->fetchAll($query);

                $html = '<select id="CLI_ID" name="CLI_ID" class="form-control required" ' . $disabled . '>';
                $html .= '<option value="">Nenhum</option>';
                foreach ($rows as $r) {
                    $select = $this->data['CLI_ID'] == $r['CLI_ID'] ? 'selected' : '';
                    $html .= '<option ' . $select . ' value="' . $r['CLI_ID'] . '">' . $r['CLI_NOM'] . '</option>';
                }
                $html .= '</select>';
                echo $html;
                ?>
            </dd>
        </div> 
        
        <div class="form-group">
            <dt><label>Funcionário</label></dt>   
            <dd> 
                <?php
                // usuario tipo funcionario
                $query = 'SELECT SQL_CACHE USU_ID,USU_NOM FROM USUARIOS WHERE USU_STA = 1 AND TUS_ID = 2 ORDER BY USU_NOM ASC';
                $rows = $this->db->fetchAll($query);

                $html = '<select id="USU_IDFUN" name="USU_IDFUN" class="form-control required" ' . $disabled . '>';
                $html .= '<option value="">Nenhum</option>';
                foreach ($rows as $r) {
                    $select = $this->data['USU_IDFUN'] == $r['USU_ID'] ? 'selected' : '';
                    $html .= '<option ' . $select . ' value="' . $r['USU_ID'] . '">' . $r['USU_NOM'] . '</option>';
                }
                $html .= '</select>';
                echo $html;
                ?>
            </dd>
        </div>
        
        <div class="form-group">
            <dt><label>Subtotal (R$)</label></dt>
            <dd> 
                <input type="text" id="PRS_VLRSUB" class="form-control" value="<?php echo $this->data['PRS_VLR'] + $this->data['PRS_VLRDSC']; ?>" readonly="">
            </dd>
        </div>

        <div class="form-group">
            <dt><label>Desconto (R$)</label></dt>
            <dd> 
                <input type="text" id="PRS_VLRDSC" name="PRS_VLRDSC" class="form-control valor_pre2" value="<?php echo $this->data['PRS_VLRDSC']; ?>" <?php echo $readonly; ?> >
            </dd>
        </div>

        <div class="form-group">
            <dt><label>TOTAL (R$)</label></dt>
            <dd> 
                <input type="text" id="PRS_VLR" name="PRS_VLR" class="form-control required" value="<?php echo $this->data['PRS_VLR']; ?>" readonly="">
            </dd>
        </div>
        
        <div class="form-group">
            <dt><label>Meio de pagamento</label></dt>   
            <dd> 
                <?php
                $query = 'SELECT SQL_CACHE TMP_ID,TMP_NOM FROM TIPO_MEIOPAGAMENTO WHERE TMP_STA = 1 ORDER BY TMP_ID ASC';
                $rows = $this->db->fetchAll($query);

                $html = '<select id="TMP_ID" name="TMP_ID" class="form-control required" ' . $disabled . '>';
                $html .= '<option value="">Nenhum</option>';
                foreach ($rows as $r) {
                    $select = $this->data['TMP_ID'] == $r['TMP_ID'] ? 'selected' : '';
                    $html .= '<option ' . $select . ' value="' . $r['TMP_ID'] . '">' . $r['TMP_NOM'] . '</option>';
                }
                $html .= '</select>';
                echo $html;
                ?>
            </dd>
        </div>

        <div class="form-group">
            <dt><label>Observação</label></dt>
            <dd> 
                <textarea id="PRS_OBS" name="PRS_OBS" class="form-control" <?php echo $readonly; ?>><?php echo $this->data['PRS_OBS']; ?></textarea>
            </dd>
        </div>

        <div class="form-group">
<?php if ($this->data['PRS_ID'] <= 0) { ?>
                <button type="button" class="btn btn-lg btn-success submit">
                    <span class="glyphicon glyphicon-floppy-saved" aria-hidden="true"></span> 
                    Salvar
                </button>
<?php } ?>
            <a href="<?php echo $this->url(array('controller' => $this->controller, 'action' => 'index', 'id' => '')); ?>" class="btn btn-lg btn-danger">
                <span class="glyphicon glyphicon-floppy-remove" aria-hidden="true"></span> 
                Cancelar
            </a>
        </div>

    </div>
</form>